﻿<Window x:Class="WpfExtras.Wizard"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:WpfExtras="clr-namespace:WpfExtras" xmlns:Converters="clr-namespace:WpfExtras.Converters" mc:Ignorable="d"
        MinHeight="377"
        MinWidth="500"
        Height="377"
        Width="500"
        Title="Wizard Title"
        WindowStyle="SingleBorderWindow"
        ResizeMode="CanResizeWithGrip"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
        ShowInTaskbar="False">

    <Window.Resources>
        <Converters:CollapseIfFalseConverter x:Key="CollapseIfFalse" />
        <HierarchicalDataTemplate x:Key="NavigationItemTemplate"
                                  ItemsSource="{Binding Children}">
            <TextBlock Text="{Binding Page.Title, UpdateSourceTrigger=PropertyChanged}" />
        </HierarchicalDataTemplate>
        <Style x:Key="TreeViewStyle"
               TargetType="{x:Type TreeView}">
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="Background"
                    Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeView}">
                        <ScrollViewer x:Name="_tv_scrollviewer_"
                                      Focusable="false"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                      CanContentScroll="false"
                                      HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                      VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="NavigationTreeViewContainer"
               TargetType="{x:Type TreeViewItem}">
            <Setter Property="Background"
                    Value="Transparent" />
            <Setter Property="HorizontalContentAlignment"
                    Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="VerticalContentAlignment"
                    Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
            <Setter Property="FontWeight"
                    Value="Normal" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="10"
                                                  Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Border x:Name="Bd"
                                    SnapsToDevicePixels="true"
                                    Grid.Column="1"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}">
                                <ContentPresenter x:Name="PART_Header"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  ContentSource="Header" />
                            </Border>
                            <ItemsPresenter x:Name="ItemsHost"
                                            Grid.Column="1"
                                            Grid.ColumnSpan="2"
                                            Grid.Row="1" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Page.IsValid}"
                             Value="False">
                    <Setter Property="Foreground"
                            Value="Red" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCurrent}"
                             Value="True">
                    <Setter Property="FontWeight"
                            Value="Bold" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="63" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="40" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TreeView Grid.Row="0"
                  Grid.Column="0"
                  Grid.RowSpan="2"
                  ItemsSource="{Binding NavigationTree}"
                  Visibility="{Binding ShowNavigationTree, Converter={StaticResource CollapseIfFalse}}"
                  ItemTemplate="{DynamicResource NavigationItemTemplate}"
                  ItemContainerStyle="{DynamicResource NavigationTreeViewContainer}"
                  Style="{DynamicResource TreeViewStyle}"
                  HorizontalAlignment="Stretch"
                  Width="150"
                  Focusable="False" />

        <DockPanel Background="{x:Static SystemColors.ControlLightLightBrush}"
                   Grid.Row="0"
                   Grid.Column="1">
            <StackPanel VerticalAlignment="Center"
                        Margin="10,0,10,0"
                        Orientation="Vertical">
                <TextBlock Text="{Binding CurrentPageContent.Title}"
                           Margin="0,0,0,5"
                           FontSize="16"
                           FontWeight="Bold" />
                <TextBlock Text="{Binding CurrentPageContent.Description}"
                           FontWeight="Bold"
                           TextWrapping="WrapWithOverflow" />
            </StackPanel>
        </DockPanel>

        <ContentPresenter x:Name="wizardPage"
                          Margin="5"
                          Grid.Row="1"
                          Grid.Column="1"
                          Content="{Binding CurrentPageContent}"
                          SnapsToDevicePixels="True" />

        <Line Grid.Row="2"
              Grid.ColumnSpan="2"
              SnapsToDevicePixels="True"
              Stretch="Fill"
              Stroke="{x:Static SystemColors.ControlDarkDarkBrush}"
              X1="0"
              X2="1" />
        <DockPanel Grid.Row="3"
                   Grid.ColumnSpan="2"
                   Margin="3">
            <StackPanel Orientation="Horizontal"
                        DockPanel.Dock="Right">
                <Button x:Name="backButton"
                        Width="75"
                        Height="23"
                        Margin="3,3,0,3"
                        Content="&lt; Back"
                        Command="{Binding Back}"
                        Loaded="OnLoaded" />
                <Button x:Name="nextButton"
                        Width="75"
                        Height="23"
                        Margin="0,3,3,3"
                        Content="Next &gt;"
                        Command="{Binding Forward}" />
                <Button x:Name="finishButton"
                        Width="75"
                        Height="23"
                        Margin="3"
                        Content="Finish"
                        Command="{Binding Finish}" />
                <Button x:Name="cancelButton"
                        Width="75"
                        Height="23"
                        Margin="3"
                        Content="Cancel"
                        Command="{Binding Cancel}" />
            </StackPanel>
            <StackPanel VerticalAlignment="Center">
                <CheckBox Content="Show Navigation Tree"
                          IsChecked="{Binding ShowNavigationTree}" />
            </StackPanel>
        </DockPanel>
    </Grid>
</Window>